package com.pd.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by dong peng on 2017/7/3.
 */
public class MyServlet extends HttpServlet {

    private int count = 0;
    Service s = new Service();

    public MyServlet(){
        System.out.println("构造servlet");
    }

    @Override
    public void init() throws ServletException {
        super.init();
        System.out.println("初始化init。。。");
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//     doPost(req,resp);
        System.out.println("doget.....");
        int i =1/0;
    }


    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        System.out.println("request entry ......" + Thread.currentThread().getName());
        String name = req.getParameter("name");
        System.out.println("name = " +name);
        count++;
        System.out.println("count = "+ count);

        s.add();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String sid = req.getSession().getId();
        System.out.println("sid="+sid);
        System.out.println("num   "+ s.getAdd());
        System.out.println("request end ......" + Thread.currentThread().getName());
        System.out.println("<---------------------------------------------------------->");

        resp.getOutputStream().write(10);



    }

    @Override
    public void destroy() {
        super.destroy();
        System.out.println("destory....");
    }
}
